Vue.config.productionTip=false  //以阻止 vue 在启动时生成生产提示。 <!-- 全局配置 -->
new Vue({
    el: '#order-app',
    data: {
        //当前登录的用户信息
        user: {
            name: 'admin',

        },
        //查看订单信息
        input: null,     //搜索内容(订单号)
        orderTime: [],    //订单时间,范围查询
        total: 0,            //总条目数
        currentPage: 1,             //当前显示页数
        pageSize: 10,        //每页所支持的最大条数
        pages : 1,           //总页数
        tableData: [        //表单内容

        ],
        //查看订单详情
        dialogReadFormVisible:false,
        elRead:{
            name:'',
            isFood: 1,
            category: '',
            nums: '',
            price:''
        },
        amount: null,     //订单总金额
        //订单详情
        orderDto: {

        },
        //效验
        rules:[

        ]
    },
    created(){
        this.init();
    },
    methods: {
        //加载列表数据
        init() {
            let reg = /^[0-9]*$/;     //输入在0-9合法
            if (reg.test(this.input)||this.input==null) {
                axios({
                    methods: "GET",
                    url: "/order/page/"+ this.currentPage + "/" + this.pageSize,
                    params:{
                        id: this.input,
                        startTime: this.orderTime[0],
                        endTime: this.orderTime[1]
                    }
                }).then((res) => {
                    if (res.data.code == 1) {
                        this.tableData = res.data.data.records;
                        this.total = parseInt(res.data.data.total);      //总条目数
                        this.pageSize = parseInt(res.data.data.size);    //每页所支持的最大条数
                        this.pages = parseInt(res.data.data.pages);      //总页数
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            } else {
                this.$message.error('请输入正确的订单号');
            }
        },
        //订单状态
        getOrderType (row) {
            let str = ''
            switch(row.status){
                case 1:
                    str =  '待付款'
                    break;
                case 2:
                    str =  '已付款'
                    break;
                case 3:
                    str =  '正在派送'
                    break;
                case 4:
                    str =  '已完成'
                    break;
                case 5:
                    str =  '已取消'
                    break;
            }
            return str
        },
        //查看订单信息
        goDetail(id){
            this.dialogReadFormVisible=true;
            axios({
                method: "POST",
                url: "/order/detail/"+id,
            }).then((res)=>{
                if(res.data.code==0){
                    this.$message.error(res.data.msg);
                }else{
                    this.orderDto=res.data.data;
                }
            });
        },
        //设置状态
        setStatus(id,status){
            this.$confirm("确定修改状态，是否继续？","提示",{
                confirmButtonText:"确定",
                cancelButtonText:"取消",
                type: "warning"
            }).then(()=> {   //选择确定的情况
                axios({
                    methods: "GET",
                    url: "/order/setStatus/"+id+"/"+status,
                }).then((res) => {
                    if (res.data.code == 1) {
                        this.$message.success({
                            message: res.data.msg,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(res.data.msg);
                    }
                }).finally(()=>{
                    this.init();
                });
            }).catch(()=>{   //选择取消的情况
                this.$message({
                    type:"into",
                    message:"已取消"
                });
            });
        },
        //每页显示的条目数改变时会触发
        handleSizeChange(val){
            this.pageSize = val;
            this.init()
        },
        //当前页改变时会触发
        handleCurrentChange(val){
            this.currentPage = val;
            this.init()
        }
    }
})